package handler

import (
	"platform/internal/svc"

	"github.com/zeromicro/go-zero/rest"
)

func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
	// 公开路由 - 登录
	server.AddRoutes(
		[]rest.Route{
			{
				Method:  "POST",
				Path:    "/api/login",
				Handler: LoginHandler(serverCtx),
			},
		},
	)

	// 需要认证的路由 - 插件管理
	server.AddRoutes(
		[]rest.Route{
			{
				Method:  "POST",
				Path:    "/api/plugins/load",
				Handler: LoadPluginHandler(serverCtx),
			},
			{
				Method:  "POST",
				Path:    "/api/plugins/unload",
				Handler: UnloadPluginHandler(serverCtx),
			},
			{
				Method:  "GET",
				Path:    "/api/plugins/list",
				Handler: ListPluginsHandler(serverCtx),
			},
			{
				Method:  "GET",
				Path:    "/api/plugins/health",
				Handler: HealthCheckHandler(serverCtx),
			},
		},
	)
	// 插件路由 - 动态分发到各个插件
	// 使用更灵活的路由匹配
	server.AddRoute(
		rest.Route{
			Method:  "GET",
			Path:    "/api/plugins/:plugin",
			Handler: PluginDispatcher(serverCtx),
		},
	)
	server.AddRoute(
		rest.Route{
			Method:  "GET",
			Path:    "/api/plugins/:plugin/:suffix",
			Handler: PluginDispatcher(serverCtx),
		},
	)
	server.AddRoute(
		rest.Route{
			Method:  "POST",
			Path:    "/api/plugins/:plugin",
			Handler: PluginDispatcher(serverCtx),
		},
	)
	server.AddRoute(
		rest.Route{
			Method:  "POST",
			Path:    "/api/plugins/:plugin/:suffix",
			Handler: PluginDispatcher(serverCtx),
		},
	)
	server.AddRoute(
		rest.Route{
			Method:  "PUT",
			Path:    "/api/plugins/:plugin",
			Handler: PluginDispatcher(serverCtx),
		},
	)
	server.AddRoute(
		rest.Route{
			Method:  "PUT",
			Path:    "/api/plugins/:plugin/:suffix",
			Handler: PluginDispatcher(serverCtx),
		},
	)
	server.AddRoute(
		rest.Route{
			Method:  "DELETE",
			Path:    "/api/plugins/:plugin",
			Handler: PluginDispatcher(serverCtx),
		},
	)
	server.AddRoute(
		rest.Route{
			Method:  "DELETE",
			Path:    "/api/plugins/:plugin/:suffix",
			Handler: PluginDispatcher(serverCtx),
		},
	)
	//// 插件路由 - 动态分发到各个插件
	//server.AddRoute(
	//	rest.Route{
	//		Method:  "GET",
	//		Path:    "/api/plugins/:plugin/*",
	//		Handler: PluginDispatcher(serverCtx),
	//	},
	//)
	//server.AddRoute(
	//	rest.Route{
	//		Method:  "POST",
	//		Path:    "/api/plugins/:plugin/*",
	//		Handler: PluginDispatcher(serverCtx),
	//	},
	//)
	//server.AddRoute(
	//	rest.Route{
	//		Method:  "PUT",
	//		Path:    "/api/plugins/:plugin/*",
	//		Handler: PluginDispatcher(serverCtx),
	//	},
	//)
	//server.AddRoute(
	//	rest.Route{
	//		Method:  "DELETE",
	//		Path:    "/api/plugins/:plugin/*",
	//		Handler: PluginDispatcher(serverCtx),
	//	},
	//)
}
